﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint.WebPartPages;
using System.ComponentModel;

namespace AsyncWebPart
{
    public class AsyncWebPartUI : WebControl
    {
        #region Private Members
        private int _startRow;
        private string _curPageName;
        private int _cacheMinutes = 0;
        #endregion

        #region Public Properties
        public string RowLimit
        {
            get;
            set;
        }

        public bool UsePaging
        {
            get;
            set;
        }

        public int CacheResultMinutes
        {
            get { return _cacheMinutes; }
            set { _cacheMinutes = value; }
        }

        public String RequestedStartRow
        {
            get;
            set;
        }

        public String CacheKey
        {
            get;
            set;
        }
        #endregion
        
        #region Constructors
        public AsyncWebPartUI(  String rowLimit, Boolean usePaging,
                                int cacheResultMinutes, String requestedStartRow, 
                                String cacheKey)
        {
            RowLimit = rowLimit;
            UsePaging = usePaging;
            CacheResultMinutes = cacheResultMinutes;
            RequestedStartRow = requestedStartRow;
            CacheKey = cacheKey;

            EnsureChildControls();
        }
        #endregion

        #region Child Controls
        protected override void CreateChildControls()
        {
            //Grab StartRow from URL Query String
            if ((RequestedStartRow == null) || (!Int32.TryParse(RequestedStartRow, out this._startRow)))
            {
                this._startRow = 0;
            }

            /* Implement the web part logic here */
            Literal litSampleText = new Literal() { Text = "Hello World!" };

            Controls.Add(litSampleText);
            base.CreateChildControls();
        }
        #endregion
    }
}
